<?php
include_once 'CF_TableEdInline.php';
class CF_TableAjax extends CF_TableEdInline{
   	/**
	 *  @var string $keyslist comma delimited list of key variables
	 */		
	var $keyslist;
   	/**
	 *  Form keylist of key columns
	 */		
	function form_keyslist(){
		$addcomma = '';
		$list = '';
		foreach($this->fieldspec AS $col_name=>$col_spec){
			if(!empty($col_spec['key'])){
				$list .= $addcomma . $col_name;
				$addcomma = ',';
				}
		}
		$this->keyslist = $list;
	}
		
	function make_rowval($value,$column){
		
		$chgname =  $this->name . ".syncVal" . "('$column', '$this->keys_uid', '$column" . "_" . "$this->keys_uid')";
		$row_text .= "<td>";
        $row_text .= $this->make_valuebox($value,$column);
        $row_text .= "</td>";
		return $row_text;			
	}

    function make_valuebox($value,$column){
      	if($this->fieldspec[$column]['show'] == 'E'){
            $chgname =  $this->name . ".syncVal" . "('$column', '$this->keys_uid', '$column" . "_" . "$this->keys_uid')";
            $row_text .= MakeEditField($this->fieldspec[$column],$column,$value,$chgname,$column . '_' . $this->keys_uid,false,$this->top_dir);
			$ov_name = $this->oldvalvar . $column;
			$row_text .= "<input type='hidden' name='$ov_name' value='$value' id='$ov_name" . "_$this->keys_uid'>";
		}  else if($this->fieldspec[$column]['show'] == 'L') {
            $row_text .= $this->make_lookup_value($column,$value);
        }else {
            $row_text .= "$value";
		}
		return $row_text;
    }

	function make_row_end($row_num){
		$rowend .= "</tr></form>\n";
		return $rowend;
	}
	
	function make_supportJS(){
		$this->form_keyslist();
		$jstext = "
	//------" .  $this->name  . " support Javascript from make_supportJS()
	//----- AJAX dataSync settings 
	// support functions in CF_ajtable.js
	$this->name = new CF_ajtable();
	$this->name.url_syncval = \"". $this->actionpage . "\";
	$this->name.keyvariables = '" . $this->keyslist . "';
	$this->name.tablename = '" . $this->name . "'	;
	// End from make_supportJS
		";
		return $jstext;
	}

}


?>
